package com.boot.unity.api.wx.controller;

import com.boot.unity.api.wx.entity.TrainAppointment;
import com.boot.unity.api.wx.service.WxAppointmentService;
import com.sun.istack.internal.NotNull;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;



/**
 * 预约培训服务
 */
@RestController
@RequestMapping("/wx/appointment")
@Validated
public class WxAppointmentController {
    private final Log logger = LogFactory.getLog(WxAppointmentController.class);

    @Autowired
    private WxAppointmentService wxAppointmentService;
    /**
     * 预约培训
     * 查询当前用户是否可进行预约
     *
     * @return
     */
    @PostMapping("mySchoolInfo")
    @GetMapping("mySchoolInfo")
    public Object mySchoolInfo(@NotNull String uid, String key) {
        return wxAppointmentService.mySchoolInfo(uid,key);
    }

    @PostMapping("save")
    public Object save(@RequestBody TrainAppointment appointment) {
        return wxAppointmentService.save(appointment);
    }


    /**
     * 教练助手 培训安排信息
     *
     * @return
     */
    @GetMapping("coachAppointList")
    public Object coachAppointList(@NotNull String uid,String key) {
        return wxAppointmentService.coachAppointList(uid,key);
    }


    /**
     * 预约签到
     *
     * @param id
     * @return
     */
    @GetMapping("signIn")
    public Object signIn(String uid, String id,String key) {
        return wxAppointmentService.signIn(uid,key,id);
    }

    /**
     * 我的教练
     * @return
     */
    @GetMapping("myCoachs")
    public Object myCoachs(String uid,String key) {
        return wxAppointmentService.myCoachs(uid,key);
    }

    /**
     * 获取预约信息
     * <p>
     */
    @GetMapping("list")
    public Object list(String uid, Integer type, String key, Integer page, Integer limit, String sort, String order) {
        if (page == null){
            page = 1;
        }
        if (limit == null){
            limit = 10;
        }
        if (sort == null){
            sort = "add_time";
        }
        if (order == null){
            order = "desc";
        }
        return wxAppointmentService.list(uid,type,key,page,limit,sort,order);
    }

}
